package com.examples.progressbar;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Monitor;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;

public class ProgressBarExample {
	
	@SuppressWarnings("rawtypes")
	public static void main(String[] args) {
		
	    final Display display = Display.getDefault();
	    
	    Monitor primary = display.getPrimaryMonitor();
	    
	    Rectangle rect = primary.getClientArea();
	    

	    @SuppressWarnings("unused")
		Class clazz = RowLayout.class;

	   // Image image = new Image(display, clazz.getResourceAsStream("pyramid.jpg"));
	    
	    final Shell shell = new Shell(display, SWT.NONE);
	    
	    RowLayout layout = new RowLayout();
	    layout.type = SWT.VERTICAL;
	    layout.fill = true;
	    shell.setLayout(layout);
	    
	    @SuppressWarnings("unused")
		Label label = new Label(shell, SWT.NONE);
	   // label.setImage(image);
	    
	    final ProgressBar progress = new ProgressBar(shell, SWT.NONE);
	    shell.pack();
	    Rectangle bounds = shell.getBounds();
	    
	    int x = rect.x + Math.max(0, (rect.width - bounds.width) / 2);
	    int y = rect.y + Math.max(0, (rect.height - bounds.height) / 2);
	    
	    shell.setBounds(x, y, bounds.width, bounds.height);
	    shell.open();
	    
	    display.timerExec(1000, new Runnable() {
	          public void run() {
	                int value = progress.getSelection();
	                if (value < 100) {
	                      progress.setSelection(value + 15);
	                      display.timerExec(1000, this);
	                } else {
	                      shell.dispose();
	                }
	          }
	    });
	    while (!shell.isDisposed()) {
	          if (!display.readAndDispatch()) display.sleep();
	    }
	  //  image.dispose();
	}
}